/*
 *  Cero Project - Copyright   2006 The Cero Developement Team 
 *  (Michael Laguerre, Camille Roux, Matthieu Segret, Mathieu Sivade) 
 * 
 *  This program is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU General Public License as published by the Free 
 *  Software Foundation; either version 2 of the License, or (at your option) 
 *  any later version.
 * 
 *  This program is distributed in the hope that it will be useful, but 
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 *  for more details.
 */

package org.ceroproject.ui.commandline.commands;

import org.ceroproject.ui.commandline.Command;
import org.ceroproject.ui.commandline.CommandLineLauncher;

public class Player extends Command {
	private static Player instance = new Player();

	protected Player() {
		super("player");
	}

	@Override
	public String toString() {
		return "change the current player";
	}

	public static Player getCommand() {
		return instance;
	}

	@Override
	public boolean executer(String parametres) {
		if (parametres.length() == 0) {
			System.out.println(CommandLineLauncher.getCurrentPlayer().getPlayerId());
			return true;
		}
		int number;
		try {
			number = Integer.valueOf(parametres);
		} catch (NumberFormatException e) {
			System.out.println("bad argument");
			return false;
		}
		try {
			CommandLineLauncher.setCurrentPlayer(CommandLineLauncher.getGame()
					.getPlayers().get(number));
		} catch (IndexOutOfBoundsException e) {
			System.out.println("This player doesn't exist");
			return false;
		}
		return true;
	}

	@Override
	public String help() {
		return "change the current player\n" +
				"syntax:\n" +
				"player  :  displays the current player's id\n" +
				"player:playernb  :  the current player becomes the player number 'playernb'\n";
	}
}
